package com.example.login_demo.slice;

import com.example.easyhttp.LogUtils;
import com.example.login_demo.ResourceTable;
import com.example.login_demo.base.BaseAbilitySlice;
import com.example.login_demo.data.DataManager;
import com.example.login_demo.utils.StringUtils;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * 注册页面
 */
public class UserRegisterAbilitySlice extends BaseAbilitySlice implements Component.ClickedListener {
    private Component mIvBack;
    private Button mBtLogin;
    private TextField mTfphone;
    private TextField mTfPassword;
    private Text mTvSendCode;
    static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");

    @Override
    public int getLayout() {
        return ResourceTable.Layout_register_layout;
    }

    @Override
    public void initView() {
        DataManager.getInstance().init(mContext);


        mIvBack = findComponentById(ResourceTable.Id_iv_back);
        mBtLogin = (Button) findComponentById(ResourceTable.Id_bt_login);
        mTfphone = (TextField) findComponentById(ResourceTable.Id_tf_phone);
        mTfPassword = (TextField) findComponentById(ResourceTable.Id_tf_password);
        mTvSendCode = (Text) findComponentById(ResourceTable.Id_tv_send_code);
    }

    @Override
    public void initListener() {
        mIvBack.setClickedListener(this);
        mBtLogin.setClickedListener(this);
        mTfphone.setClickedListener(this);
        mTfPassword.setClickedListener(this);

    }
    private String mPhone;
    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            // 后退
            case ResourceTable.Id_iv_back:
                onBackPressed();
                break;
            // 登录
            case ResourceTable.Id_bt_login:
                // 手机号
                 mPhone = mTfphone.getText();
                // 密码
                String mPassword = mTfPassword.getText();

                if (mPhone == null || "".equals(mPhone)) {
                    LogUtils.e("", "手机号不能为空");
                    return;
                }

                if (!StringUtils.isMobileNO(mPhone)) {
                    LogUtils.e("", "手机号码格式错误，请重新输入(ฅ´ω`ฅ)");
                    return;
                }
                if (mPassword == null || "".equals(mPassword)) {
                    LogUtils.e("", "密码不能为空");
                    return;
                }

                if (mPassword.length() < 6) {
                    LogUtils.e("", "\\\"密码\\\"必须是6位或以上任意字符");
                    return;
                }
                if (mPassword.length() > 18) {
                    LogUtils.e("", "\\\"密码\\\"必须是18位以内任意字符");
                    return;
                }

                LogUtils.e("", "去登陆");

                break;
            // 发送验证码
            case ResourceTable.Id_tv_send_code:
                // 手机号
                 mPhone = mTfphone.getText();

                if (mPhone == null || "".equals(mPhone)) {
                    LogUtils.e("", "手机号不能为空");
                    return;
                }

                if (!StringUtils.isMobileNO(mPhone)) {
                    LogUtils.e("", "手机号码格式错误，请重新输入(ฅ´ω`ฅ)");
                    return;
                }






                break;

        }
    }






}
